#include <bits/stdc++.h>

#define ll long long
#define ull unsigned long long
#define uint unsigned int

#define YES cout << "YES" << '\n'
#define NO cout << "NO" << '\n'
#define endl '\n'
const int INF = 1e9;
const int MOD = 998244353;
using namespace std;

/*思考

*/
void solve(){
    int x,n;
    cin>>x>>n;
    if(n%2){
        cout<<x<<endl;
    }else{
        cout<<0<<endl;
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t=0;
    cin>>t;
    while(t--){
        solve();
    }
    return 0;
}